home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 002 / today.arc / TODAY.ASM next >
Assembly Source File  |  1985-12-18  |  10KB  |  204 lines

  1. ;----------------------------------------------------------------------
  2. ; TODAY.ASM   (c) 1983
  3. ; IBM PC Macro Assembler
  4. ; Steve Manes, Roxy Recorders, NYC Sept 15, 83
  5. ; all commercial rights reserved
  6. ; Writes current system date, in correspondence form,
  7. ; to an ASCII data file DATE.DOC, on the current drive.
  8. ;
  9. ; code typed by
  10. ; Joseph MACK
  11. ; Dept. Chemistry, UMBC
  12. ; 5401 Wilkens Ave
  13. ; Catonsville,MD,21228
  14. ; 301-455-2564 (afternoons best)
  15. ; from the text of an article published in PC World, Feb'84, p212
  16. ;--------------------------------------------------------------------
  17.           Title          TODAY
  18. ;------------------;
  19. ;Program constants ;
  20. ;------------------;
  21.           cr   equ  13
  22.           lf   equ  10
  23.  
  24. CSEG     SEGMENT   PARA      'CODE'
  25. TODAY    PROC      FAR
  26.          ASSUME    CS:CSEG,DS:CSEG,ES:CSEG,SS:CSEG
  27.          ORG       100h
  28. Begin:             ; Program code begins
  29.                    ; Write intro message and fetch current system date
  30.          lea       dx,prog_name
  31.          mov       ah,9                ; PRINT STRING function
  32.          int       21h                 ; display program title
  33.          mov       ah,2Ah              ; FETCH SYSTEM DATE function
  34.          int       21h                 ; on exit : CX= Year   (1980-2099)
  35.                                        ;           DH= Month  (1-12)
  36.                                        ;           DL= Day    (1-31)
  37.          push      cx                  ; save year on stack 
  38.          push      dx                  ; save month/day on stack
  39.                    ; Position BX pointer to correct month in string
  40.          xor       bx,bx               ; clear the count register
  41.          mov       bl,dh               ; current month to BL counter
  42.          lea       di,month            ; point to top of month variable
  43.          dec       bx                  ; month=month-1
  44.          jz        write_month         ; month=0 ? (DI already positioned)
  45. month_offset:      ; Scan months for BX offset
  46.          mov       al,' '              ; char for ASCII blank
  47.          mov       cx,12               ; dummy value for SCASB instruction
  48.          repne     scasb               ; scan string
  49.          dec       bl                  ; decrement counter BL
  50.          jz        write_month         ; if BL=0, leave loop
  51.          inc       di                  ; else, offset to next character
  52.          jmp       month_offset        ;   after blank and loop again
  53. write_month:       ; Write month to DTA buffer
  54.          mov       si,di               ; Xfer string pointer to SI
  55.          lea       di,dta              ; position DI pointer to dta variable
  56.          mov       ah,' '              ; character to find
  57. w_ml:
  58.          mov       al,[si]             ; get char at SI
  59.          mov       [di],al             ; move to DTA
  60.          inc       si                  ; inc pointer registers
  61.          inc       di 
  62.          cmp       al,ah               ; see if it's an ASCII space
  63.          je        eof                 ; yes, goto eof
  64.          jmp       w_ml
  65. eof:               ; Move pointer to end of DTA string
  66.          add       di,8                ; end of text string in buffer
  67.          pop       dx                  ; restore month/day
  68.          pop       bx                  ; restore year ( orig pushed onto CX )
  69.          cmp       dl,10               ; is day a two-char print?
  70.          jb        eof1                ; no, pointer already positioned
  71.          inc       di                  ; yes, add room for another digit
  72. eof1:              ; add eof mark 1Ah
  73.                    ; Note: Only 1Ah is necc. The extra 0 is something 
  74.                    ; I always add after EOF mark for superstitious reasons
  75.                    ; mostly.
  76.          mov       byte ptr[di],0      ; put a zero there
  77.          dec       di                  ; back up string pionter
  78.          mov       byte ptr[di],26     ; put ASCII EOF mark there
  79.          push      di                  ; save ASCII end of string pointer
  80. year:              ; Write year
  81.          mov       ax,bx               ; copy year to math register
  82.          call      WRITE_ASCII         ; convert it & write it to string
  83. comma:             ; Write a comma and a blank
  84.          dec       di                  ; back up pointer
  85.          mov       byte ptr[di],' '    ; write a ' '
  86.          dec       di                  ; back up pointer
  87.          mov       byte ptr[di],','    ; write a ','
  88. day:               ; Write day of month
  89.          mov       ax,dx               ; move month/day to math register
  90.          mov       ah,0                ; clear out month
  91.          call      WRITE_ASCII         ; convert it and write it to string
  92.          pop       di                  ; restore end of ASCII string pointer
  93.                                        ; for success message print
  94.                    ; Create file directory heading
  95.          lea       dx,fcb              ; point at file control block
  96.          mov       ah,16h              ; CREAT FILE function
  97.          int       21h                 
  98.          cmp       al,0FFh             ; check status, Directory full?
  99.          je        error1              ; yes, print messg and exit
  100.                    ; Set FCB current record and random record fields
  101.          lea       si,fcb+14           ; point to record size
  102.          mov       word ptr[si],20     ; record size = 20 bytes
  103.          add       si,18               ; point to current record field
  104.          mov       byte ptr[si],0      ; current record = 0
  105.          inc       si                  ; next byte
  106.          mov       word ptr[si],0      ; random record number (low) = 0
  107.          add       si,2                ; one word over
  108.          mov       word ptr[si],0      ; random record number (high) = 0
  109.                    ; Set up DTA
  110.          lea       dx,dta              ; point at disk transfer buffer
  111.          mov       ah,1Ah              ; Set DISK TRANSFER ADDRESS funct
  112.          int       21h
  113.                    ; Write data to disk
  114.          lea       dx,fcb
  115.          mov       cx,1                ; # of records to write
  116.          mov       ah,22h              ; RANDOM WRITE function
  117.          int       21h 
  118.          cmp       al,1                ; disk full?
  119.          je        error2              ; yes, print error mssg
  120.                    ; Record written successfully. Close file & exit
  121.          lea       dx,fcb
  122.          mov       ah,10h              ; CLOSE FILE function
  123.          int       21h                
  124.          cmp       al,0FFh             ; check status. File closed properly ?
  125.          je        error3              ; no, print error mssg
  126.          mov       byte ptr[di],'$'    ; replace EOF mark with EOS char
  127.                                        ;    for video display of date
  128.          lea       dx,success          ; point to success mssg and exit
  129.          jmp       exit
  130. error1:
  131.          lea       dx,failure1         ; point to error mssg
  132.          jmp       exit                ; and exit
  133. error2:
  134.          lea       dx,failure2         
  135.          jmp       exit
  136. error3:
  137.          lea       dx,failure3
  138.          jmp       exit
  139. exit: 
  140.          mov       ah,9                ; PRINT STRING function
  141.          int       21h                 ; print DX mssg
  142.          lea       dx,cr_lf            ; cr,lf sequence
  143.          mov       ah,9                ; PRINT STRING function
  144.          int       21h     
  145.          int       20h                 ; & exit to DOS
  146.  
  147. WRITE_ASCII        PROC
  148.                    ; This proc converts and unsigned binary number 
  149.                    ; to an ASCII string pointed at by DI
  150.                    ; At entry, AX= number to be converted
  151.                    ;           DI= character designation address +1
  152.          push      dx                  ; save registers used
  153.          push      si
  154.          mov       si,10               ; divisor
  155. convert:
  156.          xor       dx,dx               ; clear remainder register
  157.          div       si                  ; divide AX by 10
  158.          add       dx,'0'              ; cnvert dx remainder to ASCII
  159.          dec       di                  ; back up string pointer
  160.          mov       byte ptr[di],dl     ; write ASCII number to DI string
  161.          cmp       ax,0                ; finished?
  162.          ja        convert             ; no, convert next number
  163.          pop       si                  ; yes, restore registers
  164.          pop       dx            
  165.          ret                           ; ret to caller
  166. WRITE_ASCII        ENDP
  167. TODAY              ENDP                ; end of executable code
  168. ;----------------------;
  169. ; Program data         ;
  170. ;----------------------;
  171.          fcb       db   0,'DATE    DOC'; Standard file control
  172.                    db   28 dup(0)
  173. month              db   'January '
  174.                    db   'February '
  175.                    db   'March '
  176.                    db   'April '
  177.                    db   'May ' 
  178.                    db   'June '
  179.                    db   'July '
  180.                    db   'August '
  181.                    db   'September '
  182.                    db   'October '
  183.                    db   'November '
  184.                    db   'December '
  185. prog_name          db   cr,lf,"TODAY.COM (c) 1983 Steve Manes",cr,lf,'$'
  186.                    ; Note, there is no '$' char after a success mssg
  187.                    ; The program will supply this
  188. success            db   "Today's date written to DATE.DOC",cr,lf
  189. dta                db    21 dup(' ')    ; disk transfer buffer
  190. failure1           db   "Directory Full$"
  191. failure2           db   "Disk Full$"
  192. failure3           db   "File close error$"
  193.      cr_lf         db   cr,lf,'$'       ; cr,lf
  194.  
  195. CSEG    ENDS                            ; end of seg
  196.         END        BEGIN                ; end of assembly
  197. Author : Steve Manes
  198.          Roxy Recorders Inc
  199.          648 Broadway
  200.          NYC,NY,10012
  201.          (212)-533-1692
  202.          (212)-475-6571
  203.  
  204.